package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    /**
     * 统计log表中，今日注册人数、登录数
     */
    @Select("select count(*) from tb_log where log_time = #{now} and type = #{type}")
    Long queryNumsByType(@Param("now") String now, @Param("type") String type);

    /**
     * 统计log表中，活跃用户数
     */
    @Select("select count(DISTINCT user_id) from tb_log where log_time = #{now}")
    Long queryNumsByDate(@Param("now") String now);

    /**
     * 统计log表中，次日留存用户数
     */
    @Select("select count(DISTINCT user_id) from tb_log where log_time = #{now} and user_id in " +
            "(select user_id from tb_log where log_time = #{yes} and type = '0102')")
    Long queryRetention1d(@Param("now") String now, @Param("yes") String yes);
}